home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / editor / remote.zip / remote.js < prev   
Text File  |  1997-06-24  |  7KB  |  178 lines

  1. // This JavaScript remote-control search engine interface
  2. // was written by Curtis Autery on June 24, 1997
  3. // as a modification of a previous interface by Curtis Autery.
  4. // This document is in the public domain and can be used for
  5. // helping to learn JavaScript by example. Cut and paste at will,
  6. // but leave this notice intact as a courtesy. Thank you.
  7.  
  8.  
  9. // First a note : This is not written as a JavaScript reference. It can be used
  10. // for some examples of organizing JavaScript concepts to those already
  11. // thoroughly familiar with the language.
  12.  
  13.  
  14. // As this is a remote control box, I want it to stay on top in some circumstances,
  15. // but not in others. I'll start by declaring a global variable outside of the
  16. // main functions.
  17. keepfocus=1
  18.  
  19.  
  20.  
  21. // This is the basic remote control opener function. It opens a 200x100 window with
  22. // no "extras" like toolbars or scrollbars, and is a fixed size that cannot be resized
  23. // (although it can be maximized, but there's no point in that). The document.clear function
  24. // only works in Netscape 3 and above (and IE 3, I think, but I wouldn't try using this
  25. // in any other version of IE except IE4), so this will not work in Netscape 2.x. I am
  26. // using the document.clear function just in case the load function gets called twice so the
  27. // text that I'm sending to the window won't be sent twice.
  28. function rcopen() {
  29. keepfocus=1;
  30. rcbox=window.open("", "info","resizable=0,toolbar=0,menubar=0,scrollbars=0,width=200,height=100");
  31. rcbox.document.clear();
  32. rcbox.focus();
  33. rcbox.opener.name="orig";
  34.  
  35. // Note that I has to break up <scr and ipt>. JavaScript will have a cow
  36. // if you try to send a direct script tag to another window. The source for the RC
  37. // window will be this document. If you modify this document and save it under a new
  38. // name, be sure to modify the following line accordingly.
  39. rcbox.document.write("<head><scr"+"ipt src=remote.js></script>");
  40.  
  41. // Title's the window and turns focus to "always on" when window get focus,
  42. // as well us checking to see if focus should be returned whenever focus goes
  43. // to another item (onBlur). Note my use of a timer here. This is so that
  44. // I have time to turn off the auto-focus when items in the RC window are
  45. // selected. This was a major pain to get setup properly
  46. rcbox.document.write("<title>Remote Control</title></head><body onfocus='wax()' onblur=\"timerID=setTimeout('dofocus()',50)\">");
  47. }
  48.  
  49.  
  50. // The following section is all the focus related commands. DoFocus checks to see
  51. // if focus should be returned. Wain turns off auto-focus, Wax turns it on.
  52.  
  53. function dofocus(){
  54. if (keepfocus==1) 
  55. {window.focus();}
  56. }
  57.  
  58. function wain(){keepfocus=0;}
  59. function wax(){keepfocus=1;}
  60.  
  61. // FocusOn turns on auto-focus AND returns the RC focus in one command.
  62. // ReturnControl does the opposite, turning auto-focus off and returning focus to the
  63. // main web page
  64.  
  65. function focuson(){keepfocus=1;window.focus()}
  66. function returncontrol(){keepfocus=0;opener.focus();}
  67.  
  68.  
  69. // A timesaving "alias" function so that I don't have to type "rxbox.document.write"
  70. // everytime I want to send text to the RC box.
  71. function rc(text) {
  72. rcbox.document.write (text);
  73. }
  74.  
  75. // Puts the "Hide" button on the bottom of the form that gets rid of the RC
  76. // box so that the user can manipulate the destination page.
  77. // bringing the RC box back up will return the auto-focus property until Hide
  78. // is pressed again
  79. function button(){
  80. rc("<input type=button value=Hide onclick='returncontrol()'></center><br>");
  81. rc("</form></html>");
  82. }
  83.  
  84.  
  85. // This function directs the main "opener" page to the search engine of choice using
  86. // the entered terms from one of the functions below
  87. function go(terms){
  88. focuson();
  89. opener.location.href=("http://"+terms);
  90. }
  91.  
  92. // Below are the functions describing the syntax of each individual search engine.
  93. // These change, and so do the URLs. These were accurate as of the date of this
  94. // file's creation
  95.  
  96. function yahoo(terms) {
  97. go("search.yahoo.com/bin/search?p="+terms)}
  98.  
  99. function webcrawler(terms) {
  100. go("www.webcrawler.com/cgi-bin/WebQuery?searchText="+terms)}
  101.  
  102. function lycos(terms) {
  103. go("www.lycos.com/cgi-bin/pursuit?query="+terms)}
  104.  
  105. function alta(terms) {
  106. go("www.altavista.digital.com/cgi-bin/query?pg=q&what=web&q="+terms)}
  107.  
  108. function hotbot(terms) {
  109. go("www.hotbot.com/?MT="+terms)}
  110.  
  111. function excite(terms) {
  112. go("www.excite.com/search.gw?search="+terms)}
  113.  
  114. function magellan(terms) {
  115. go("www.mckinley.com/searcher.cgi?query="+terms)}
  116.  
  117. function infoseek(terms) {
  118. go("www.infoseek.com/Titles?sv=IS&lk=noframes&nh=10&qt="+terms)}
  119.  
  120. function metacrawler(terms) {
  121. go("www2.metacrawler.com/cgi-bin/nph-metaquery?method=0&sort=relevance<arget=window&useFrames=1&iface=int1&general="+terms)}
  122.  
  123. function savvy(terms) {
  124. go("rampal.cs.colostate.edu:2000/search?KW="+terms)}
  125.  
  126.  
  127.  
  128. // A quick function determining which item of the selector was chosen. This will forward
  129. // the search terms to the appropriate engine function above
  130. function search(engine,terms){
  131. focuson();
  132. if (engine==0) yahoo(terms);
  133. else if (engine==1) webcrawler(terms);
  134. else if (engine==2) lycos(terms);
  135. else if (engine==3) alta(terms);
  136. else if (engine==4) hotbot(terms);
  137. else if (engine==5) excite(terms);
  138. else if (engine==6) magellan(terms);
  139. else if (engine==7) infoseek(terms);
  140. else if (engine==8) metacrawler(terms);
  141. else if (engine==9) savvy(terms);
  142. else if (engine>=10) direct(engine);
  143. }
  144. // If the selector was set to the bottom entry, "Delirium's Homepage", then
  145. // a special function is called. More items can be added to this. If you want to add your
  146. // homepage to the list, add "else if (engine==11) mypage();" to the Direct function,
  147. // then create a function "function mypage()" similar to the Delirium function below
  148. function direct(engine){
  149. if (engine==10) delirium();
  150. }
  151.  
  152. function delirium(){go("ourworld.compuserve.com/homepages/delirium")}
  153.  
  154.  
  155.  
  156. // This is the main function that is called from the rc.htm file when it is opened.
  157. // This will call the RC box open function, and send some HTML code to it.
  158. function doit(){
  159. rcopen();
  160. rc("<body bgcolor=black>");
  161. rc("<form name=selector action=\"javascript:search(document.selector[0].selectedIndex,escape(document.selector[1].value))\" method=post>");
  162. rc("<select name=\"engine\" onfocus='wain()' onchange='focuson()' onblur='dofocus()'>");
  163. rc("<option value=0>Yahoo");
  164. rc("<option value=1 SELECTED>Webcrawler");
  165. rc("<option value=2>Lycos");
  166. rc("<option value=3>Alta-Vista");
  167. rc("<option value=4>Hotbot");
  168. rc("<option value=5>Excite");
  169. rc("<option value=6>Magellan");
  170. rc("<option value=7>Infoseek");
  171. rc("<option value=8>Metacrawler");
  172. rc("<option value=9>Savvy Search");
  173. rc("<option value=10>Delirium's Homepage");
  174. rc("</select>");
  175. rc("<br><input type=text name=\"terms\" value=\"\" size=20 onfocus='wain()' onchange='focuson()' onblur='dofocus()'>");
  176. rc("<br><input type=submit value=Go> ");
  177. button();
  178. }